package com.wiscamp.ninechapters.challenges.infrastructure.mappers;

import com.wiscamp.ninechapters.challenges.infrastructure.po.InviteHelpPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

@Repository
public interface InviteHelpMapper extends JpaRepository<InviteHelpPO, Long>, JpaSpecificationExecutor<InviteHelpPO> {

    /**
     * 通过助力用户编号和日期获取邀请助力
     *
     * @param userId
     * @param year
     * @param month
     * @param day
     * @param supporterId
     * @return
     */

    @Query(value = "select e from InviteHelpPO e where e.userId = :userId and e.dateYear = :year and e.dateMonth = :month and e.dateDay = :day and e.supporterId = :supporterId")
    InviteHelpPO getInviteHelp(long userId, int year, int month, int day, long supporterId);

    /**
     * 通过用户编号和日期获取邀请助力列表
     *
     * @param userId
     * @param year
     * @param month
     * @param day
     * @return
     */

    @Query(value = "select e from InviteHelpPO e where e.userId = :userId and e.dateYear = :year and e.dateMonth = :month and e.dateDay = :day")
    Collection<InviteHelpPO> getInviteHelps(long userId, int year, int month, int day);
}